<div data-dux="table-bind">
    <div class="dux-page-header am-cf">
        <div class="page-title">
            <a class="am-btn am-btn-primary" href="javascript:;" id="update"> 上传菜单</a>
        </div>
        <div class="page-action">
            <a class="am-btn am-btn-primary" href="{url('add')}">添加</a>
        </div>
    </div>
    <div class="dux-page-table">
        <table class="am-table dux-table" data-table>
            <thead>
            <tr>
                <th>菜单名称</th>
                <th>菜单类型</th>
                <th>触发内容</th>
                <th class="am-text-center" width="120">管理</th>
            </tr>
            </thead>
            <tbody>
            <!--loop{$list as $vo}-->
            <tr>
                <td>{$vo.cname}</td>
                <td>
                    {$vo.type ? '关键词' : '跳转'}
                </td>
                <td class="am-text-break">{str_len($vo.key, 50)}</td>
                <td class="am-text-center">
                    <a class="am-btn am-btn-primary am-btn-xs" href="{url('edit', ['id'=>$vo[$pri]])}" title="编辑"><i class="am-icon-pencil"></i></a>
                    <a class="am-btn am-btn-danger am-btn-xs" href="javascript:;" data-url="{url('del')}" data-id="{$vo[$pri]}" title="删除" data-del><i class=" am-icon-trash"></i></a>
                </td>
            </tr>
            <!--{/loop}-->
            </tbody>
        </table>
    </div>
    <div class="dux-page-foot am-cf">
        {$page}
    </div>
</div>

<script>
    Do('base', 'dialog', function () {
        var dialog = null;
        var sync = function (pageNum) {
            app.debug(pageNum);
            app.ajax({
                url: '{url("sync")}',
                type: 'post',
                data: {
                    page: pageNum
                },
                tip: false,
                success: function (info) {
                    layer.close(dialog);
                    dialog = layer.msg('素材完成页数(' + info.num + '/' + info.max + ')', {
                        time : 200000
                    });
                    sync(pageNum + 1);
                },
                error : function(msg, url) {
                    layer.close(dialog);
                    layer.msg(msg);
                    if(url) {
                        setTimeout(function() {
                            window.location.href = url;
                        }, 2000);
                    }
                }
            });

        };

        $('#update').click(function () {
            layer.confirm('上传菜单将删除现有菜单,请确认？', {
                btn: ['上传','取消'] //按钮
            }, function(index){
                dialog = layer.msg('上传中,请稍等!');
                app.ajax({
                    url: '{url("updateMenu")}',
                    type: 'post',
                    data: {},
                    tip: false,
                    success: function (msg) {
                        layer.close(dialog);
                        dialog = layer.msg(msg);
                    },
                    error : function(msg, url) {
                        layer.close(dialog);
                        layer.msg(msg);
                    }
                });

            });

        });

    });
</script>